<template>
	<div>
		<carHeader :title="'活动发布'"></carHeader>
		<!-- <u-popup :show="open" mode="center" :round="10">
			<view class="popup">
				<view class="text">
					<text>您确定要执行这样的操作吗?</text>
				</view>
				<view class="button">
					<u-button class="btn1" @click="cancel()">取消</u-button>
					<u-button class="btn2" @click="submitBtn(item)">确认</u-button>
				</view>

			</view>
		</u-popup> -->
		<u-notify ref="uNotify" message="操作成功" @click="submitBtn()"></u-notify>
		<div class="zong">
			<div class="head">
				<div class="body">
					<div class="body1">
						<div class="bodyhead">
							<div class="son1">
								<div class="son11" :class="{ 'item': true, 'active': activeIndex === 1}"
									@click="changeColor()">
									<span>已上架</span>
								</div>
								<div class="son12" :class="{ 'item': true, 'active': activeIndex === 0 }"
									@click="changeColor1()">
									<span>未上架</span>
								</div>
							</div>
						</div>

						<div v-if="activeIndex===1" v-for="(item,index) in yishanglist" :key="index">
							<div class="bodyhead22" @click="navigateToDetail2(item)">
								<p>{{item.title}}</p>
								<p style="color: #bbbbbb;">{{item.publishTime}}</p>
								<button type="primary" class="sonson1" @click="handleClick1(item)">下架</button>
							</div>

						</div>

						<div v-if="activeIndex===0" v-for="(item,index) in weishanglist">

							<div class="bodyhead2" @click="navigateToDetail2(item)">
								<p>{{item.title}}</p>
								<p>
									<span
										:class="{'color1':true,'color11':item.zhuangtai===1,'color111':item.zhuangtai===2}">{{getStatusText(item.zhuangtai)}}</span>
								<div v-if="item.zhuangtai === 0 || item.zhuangtai === 2">
									<button type="primary" class="sonson2" @click.stop="handleClick3(item)">删除</button>
								</div>
								<div v-if="item.zhuangtai === 1">
									<button type="primary" class="sonson2" @click.stop="handleClick2(item)">上架</button>
								</div>

								</p>
								<p style="color:#bbbbbb; position: relative; top: -30px;">{{item.publishTime}}</p>
							</div>
						</div>
						<navigator url="/pages/announceActivity/announceActivity">
							<button type="primary" class="hail">+发布活动</button>
						</navigator>
					</div>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
	import index from '../../uni_modules/uview-ui';
	export default {
		data() {
			return {
				open: false,
				show: true,
				index: 0,
				activeIndex: 1,
				index1: '',
				// listheight:200,
				yishanglist: [],
				weishanglist: [],
				message: {},
				// show: false,
			}
		},
		created() {
			this.changeColor();
		},
		onReady() {},
		methods: {
			getStatusText(status) {
				switch (status) {
					case 0:
						return '待审核';
					case 1:
						return '审核通过';
					case 2:
						return '审核失败';
					// default:
					// 	return '未知状态';
				}
			},
			changeColor() {
				this.activeIndex = 1;
				const that = this;
				uni.request({
					url: "http://localhost:8080/shop/activity/list",
					method: 'POST',
					// header: {
					// 	"Authorization": "Bearer eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VyX2tleSI6ImJmMzQ4YzRjLTEzNmMtNGIyOS1hZjY4LWViMzI5YTVjYzNiMCIsInVzZXJuYW1lIjoiYWRtaW4ifQ.C2ALXJ99FQY03CVXw0dbOirfokIMIJv0TKEZwUKfpdn2QHoYuoTumQlnA54BBQeItgnEU8h3mkNJwd7ngKXG1g"
					// },
					data: {
						storeId: this.$global.shopId,
						status: 1
					},
					success(res) {
						that.yishanglist = res.data.rows;
						that.isLoading = false; // 数据加载完成，更新加载状态 
					}
				})
			},
			changeColor1() {
				this.activeIndex = 0;
				const that = this;
				uni.request({
					url: "http://localhost:8080/shop/activity/list",
					method: 'POST',
					// header: {
					// 	"Authorization": "Bearer eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VyX2tleSI6ImJmMzQ4YzRjLTEzNmMtNGIyOS1hZjY4LWViMzI5YTVjYzNiMCIsInVzZXJuYW1lIjoiYWRtaW4ifQ.C2ALXJ99FQY03CVXw0dbOirfokIMIJv0TKEZwUKfpdn2QHoYuoTumQlnA54BBQeItgnEU8h3mkNJwd7ngKXG1g"
					// },
					data: {
						storeId: this.$global.shopId,
						status: 0
					},	
					success(res) {
						// console.log(res);
						// console.log(res.data);
						// console.log("请求成功",res);
						that.weishanglist = res.data.rows;
						// that.weishanglist = res.data.rows;
						console.log(that.weishanglist);
						that.isLoading = false; // 数据加载完成，更新加载状态 
					}
				})
			},
			navigateToDetail(obj) {
				console.log(obj);
				const url = `/pages/activityDetail/activityDetail?data=${encodeURIComponent(JSON.stringify(obj))}`;
				uni.navigateTo({
					url: url
				});
			},
			navigateToDetail2(obj) {
				console.log(obj);
				const url = `/pages/activityDetail/activityDetail?data=${encodeURIComponent(JSON.stringify(obj))}`;
				uni.navigateTo({
					url: url
				});
			},
			// handleClick(item) {
			// 	this.message = item;
			// 	console.log(this.message.publishId);
			// 	this.open = true;
			// },
			handleClick1(item) {
				this.message = item;
				console.log(this.message.publishId);
				uni.request({
					url: "http://localhost:8080/shop/activity/update",
					data: {
						publishId: this.message.publishId,
						status: 0,
						zhuangtai: this.message.zhuangtai
					},
					method: 'PUT',
					success(res) {
						console.log(res);
				
					}
				})
			},
			handleClick2(item) {
				this.message = item;
				console.log(this.message.publishId);
				uni.request({
					url: "http://localhost:8080/shop/activity/update",
					data: {
						publishId: this.message.publishId,
						status: 1,
						zhuangtai: this.message.zhuangtai
					},
					method: 'PUT',
					success(res) {
						console.log(res);
					
				
					}
				})
			},
			handleClick3(item) {
				this.message = item;
				console.log(this.message.publishId);
				uni.request({
					url: "http://localhost:8080/shop/activity/delete/"+this.message.publishId,
					
					method: 'DELETE',
					success(res) {
						console.log(res);
					
				
					}
				})
			},
			cancel() {
				this.open = false;
			},
			submitBtn(item) {
				this.message = item;
				this.$refs.uNotify.show({
					top: 40,
					type: 'success',
					color: '#eeeeee',
					bgColor: '#5ad327  ',
					message: '操作成功',
					duration: 1000 * 3,
					fontSize: 20,
					safeAreaInsetTop: true
				})
				
					uni.request({
						url: "http://localhost:8080/shop/activity/delete/"+this.message.publishId,
						
						method: 'DELETE',
						success(res) {
							console.log(res);
							this.open = false;
					
						}
					})
				
			}
		}

	}
</script>

<style>
	.popup {
		width: 100%;
		background-color: #eeeeee;
		border-radius: 10px;
	}

	.button {
		/* background-color: #009AFF; */
		display: flex;
		justify-content: center;
		margin-top: 10px;
	}

	.btn1 {
		/* border-radius: 10px; */
		background-color: #bbbbbb;
		/* margin-bottom: 5px; */
	}

	.btn2 {
		background-color: #009AFF;
		color: #ffffff;
	}

	.text {
		padding: 20px 30px;
	}

	.color1 {
		color: red;
	}

	.color11 {
		color: greenyellow;
	}

	.color111 {
		color: #bbbbbb;
	}

	* {
		margin: 0;
		padding: 0;
	}

	.zong {
		height: 1300rpx;
		width: 100%;
		background-color: #eeeeee;
		position: relative;
		float: left;
		top: -130px;
	}

	.head {
		height: 340rpx;
		background-color: #2276FF;
		padding-top: 10px;

	}

	.body {
		display: flex;
		background-color: #ffffff;
		/* height: 950rpx; */
		width: 700rpx;
		margin: 0 auto;
		border-radius: 20px;

	}

	.body.bodyheight {
		display: flex;
		height: 530rpx;
		/* 	height: listheight+'px'; */
	}

	.body1 {
		margin: 0 auto;
		/* 	background-color: aquamarine; */
		width: 650rpx;
		/* 	height: 710rpx; */
	}

	.bodyhead {
		height: 125rpx;
		/* 	background-color: aliceblue; */
		border-bottom: 3px solid #eeeeee;
		padding-top: 25px;

	}

	.bodyhead2 {
		height: 230rpx;
		border-bottom: 2px solid #eeeeee;

	}

	.bodyhead22 {
		height: 140rpx;
		border-bottom: 2px solid #eeeeee;

	}

	.bodyhead3 {
		height: 230rpx;
		border-bottom: 2px solid #eeeeee;

	}

	.bodyhead33 {
		height: 140rpx;

	}

	.son1 {
		height: 40px;
		margin: 0 auto;
		width: 150px;
		background-color: pink;
		/* padding-top: 10px; */
		border-radius: 30px;
		text-align: center;
		line-height: 40px;
		border: 1px solid #eeeeee;
		/* margin-top: 10px; */
	}

	.son11 {
		float: left;
		height: 40px;
		width: 75px;
		background-color: #eeeeee;
		color: #009AFF;
		border-top-left-radius: 20px;
		border-bottom-left-radius: 20px;
	}

	.son12 {
		float: left;
		height: 40px;
		width: 75px;
		background-color: #009AFF;
		color: #eeeeee;
		border-top-right-radius: 20px;
		border-bottom-right-radius: 20px;
	}

	.item {
		color: #2276FF;
		background-color: #eeeeee;
		font-size: 16px;
	}

	.item.active {
		color: #eeeeee;
		background-color: #2276FF;
	}

	p {
		margin-top: 15px;
	}

	.sonson {
		margin-left: 200px;

		background-color: #009AFF;

		padding: 5px 20px 5px 20px;
		border-radius: 20px;

	}

	.sonson1 {
		/* margin-left: 200px; */
		background-color: #2276FF;
		border-radius: 20px;
		position: relative;
		font-size: 16px;
		line-height: 60rpx;
		width: 160rpx;
		height: 60rpx;
		left: 130px;
		top: -45px;

	}

	.sonson2 {
		/* margin-left: 200px; */
		background-color: #2276FF;
		border-radius: 20px;
		/* 	position: relative; */
		font-size: 16px;
		line-height: 60rpx;
		width: 160rpx;
		height: 60rpx;
		left: 130px;
		top: -30px;

	}

	.bodyhead3 .sonson {
		margin-left: 180px;
	}

	.hail {
		height: 40px;
		width: 250px;
		background-color: #2276FF;
		margin: 0 auto;
		margin-top: 20px;
		margin-bottom: 20px;
		border-radius: 20px;
		/* text-align: center; */
		line-height: 40px;
		font-size: 18px;
		/* color: #ffffff; */
		/* position: fixed; */
	}
</style>